home *** CD-ROM | disk | FTP | other *** search
AMOS Source Code | 1992-09-28 | 5.3 KB | 169 lines |
- '***************************
- '* AMOS Professional *
- '* *
- '* COMPUTED SPRITES *
- '* *
- '* (c) Europress Software *
- '* *
- '* Ronnie Simpson *
- '***************************
- '
- '-------------------
- 'GENERAL
- '-------------------
- 'The maximum of 8 hardware sprites would obviously be a big drawback, but
- 'AMOS Professional allows each of these sprites to be sliced into a number
- 'of segments giving a set of 'computed sprites'.
- 'The sprite numbers 0-7 are reserved for the individual hardware sprites so
- 'computed sprite numbers start from 8 upwards to a maximum of 63.
- '
- '-------------------
- 'LIMITATIONS
- '-------------------
- 'Before you start using the computed sprites there are a number of
- 'restrictions that you must be aware of.
- '
- '1) The same width and colour restrictions of the hardware sprites apply
- ' equally to computed sprites ie. a maximum of 128 pixels wide in total
- ' per horizontal line in the 3 colour mode or 64 pixels wide in the 15
- ' colour mode.
- '
- '2) Another unavoidable side effect is that a 1 pixel wide gap must be left
- ' between segments taken from any one hardware sprite.
- ' +----------+
- 'eg. | sprite 8 |
- ' +----------+----------+ ----a 1 pixel gap must be left to
- ' | sprite 9 | avoid any overlap.
- ' +----------+
- '
- '3) Computed sprites are managed by the software, so you never know exactly
- ' which hardware sprite is being used to display your image.
- '
- '4) The mouse pointer is normally used by hardware sprite 0, you will have
- ' to free this with the Hide instruction if you wish to have the maximum
- ' number of computed sprites.
- '
- 'If any of the above restrictions are ignored then no error will be
- 'generated but it will result in the unexpected disappearance of some
- 'of the computed sprites from the screen.
- '
- '-------------------
- 'OVERVIEW
- '-------------------
- 'There are a total of 8 hardware sprites each 16 pixels wide by 255 high.
- '
- 'Each hardware sprite can be cut into slices which are controlled by the
- 'software -these are the computed sprites.
- '
- 'Each computed sprite taken from any one hardware sprite must be spaced
- 'on the screen with at least a 1 pixel gap between. (vertically)
- '
- 'The same restrictions of hardware sprites of size and number of colours
- 'apply to computed sprites.
- '
- 'Computed sprites joined or overlaid to increase size or number of colours
- 'are managed by the system and require no further user control.
- '
- 'If restrictions on total width are exceeded then some computed sprites will
- 'not be displayed.
- '
- '-------------------
- 'WIDTH RESTRICTIONS
- '-------------------
- 'The formula for maximum width:-
- '
- '1) Add together the maximum total width of all the 3 colour sprites that
- ' may have to share the same horizontal line.
- '
- '2) Do the same for your 15 colour sprites and double this value.
- '
- '3) Add together values from 1 and 2.
- '
- 'The total value must never be more than 128 pixels or this will result in
- 'some sprites not being displayed.
- '
- '-------------------
- 'SPRITE UPDATES
- '-------------------
- 'Normally whenever a sprite is moved the position is updated at the next
- 'vertical blank. If a large number of sprites are being moved there may not
- 'be enough time to move them all 1/50th. of a second resulting
- 'in a noticeable jump in the sprite movements. Under these circumstances it
- 'may become necessary to turn off the automatic updating with Sprite Update
- 'Off. Once the new sprite positions have all been calculated they can be
- 'flicked into place with a call to Sprite Update.
- '
- 'eg. Sprite Update Off
- ' Do
- ' Rem **** move all the sprites
- ' Sprite Update
- ' Loop
- '
- 'The normal automatic system may be turned back on at any time with a single
- 'call to Sprite Update On.
- '
- '-------------------
- 'WORKING EXAMPLE
- '-------------------
- Rem *** dimension arrays which hold coordinates and directions
- '
- Dim X(63),Y(63),I(63)
- '
- '
- Rem *** load some sprite images
- '
- Load "AMOSPro_Tutorial:Objects/Sprites.abk"
- '
- '
- Rem *** set the palette and change the colour indexes 16 to 31 used by sprites
- '
- Flash Off : Get Sprite Palette
- Curs Off : Cls 0 : Hide
- For N=15 To 28 Step 4
- Colour N+1,0 : Colour N+2,$81F : Colour N+3,$FF0 : Colour N+4,$F00
- Next
- '
- '
- Rem *** plot some stars and bars
- '
- For N=1 To 100
- X=Rnd(319) : Y=Rnd(199) : Plot X,Y
- Next
- Ink 7
- For X=1 To 3
- Bar X*70,180 To X*70+30,199
- Next
- Pen 8 : Paper 0 : Centre "PRESS ANY MOUSE KEY TO QUIT"
- '
- '
- Rem *** set the start positions of compured sprites
- '
- For N=0 To 7
- X(N+8)=N*25+150 : Y(N+8)=175 : I(N+8)=7
- X(N+16)=N*25+150 : Y(N+16)=155 : I(N+16)=7
- X(N+24)=N*25+150 : Y(N+24)=135 : I(N+24)=7
- X(N+32)=N*25+150 : Y(N+32)=115 : I(N+32)=7
- X(N+40)=N*25+150 : Y(N+40)=95 : I(N+40)=7
- X(N+48)=N*25+150 : Y(N+48)=75 : I(N+48)=7
- Next
- '
- '
- COUNT=8 : COUNTB=55
- Rem *** start main loop
- '
- DX=1
- Do
- If X(8)<128 or X(15)>434 Then DX=-DX
- For N=8 To 55
- If N=8 and I(COUNT)=7 and Rnd(3)=1 Then COUNT=Rnd(47)+8
- If N=9 Then Add COUNTB,1,8 To 55 : Add I(COUNTB),1,7 To 8
- If N mod 6=1 Then Add I(COUNT),1 : If I(COUNT)=12 Then I(COUNT)=7
- Add X(N),DX
- Sprite N,X(N),Y(N),I(N)
- Next
- Exit If Mouse Key
- Loop
- If N=8 Then Add COUNT,1,8 To 55 : Add I(COUNT),1,7 To 8
- '
- '
- Edit